package yxy.game.pm2.module.gacha;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;

import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.summonpooldate;

public class GachaHeroBean {
    private int dataId;
    private GachaHeroType gachaType;
    private DateTime updateTime;
    private int freeTimes;// 免费次数
    private int times;// 招募次数
    private boolean gachaed;
    private int thirtyTimes;// 30次保底记录
    private int timesForMusthit;// 记录每个玩家第一次和第二次十连的保底，必须20资质和21资质以上
    private DateTime pointsResetTime ;//积分重置时间记录

    public int getThirtyTimes() {
        return thirtyTimes;
    }

    public void setThirtyTimes(int thirtyTimes) {
        this.thirtyTimes = thirtyTimes;
    }

    public int getDataId() {
        return dataId;
    }

    public void setDataId(int dataId) {
        this.dataId = dataId;
    }

    public GachaHeroType getGachaType() {
        return gachaType;
    }

    public void setGachaType(GachaHeroType gachaType) {
        this.gachaType = gachaType;
    }

    public DateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(DateTime updateTime) {
        this.updateTime = updateTime;
    }

    public int getFreeTimes() {
        return freeTimes;
    }

    public void setFreeTimes(int freeTimes) {
        this.freeTimes = freeTimes;
    }

    public int getTimes() {
        return times;
    }

    public void setTimes(int times) {
        this.times = times;
    }

    public boolean isGachaed() {
        return gachaed;
    }

    public void setGachaed(boolean gachaed) {
        this.gachaed = gachaed;
    }

    public DateTime getPointsResetTime() {
        return pointsResetTime;
    }

    public void setPointsResetTime(DateTime pointsResetTime) {
        this.pointsResetTime = pointsResetTime;
    }

    public int getTimesForMusthit() {
        return timesForMusthit;
    }

    public void setTimesForMusthit(int timesForMusthit) {
        this.timesForMusthit = timesForMusthit;
    }
    // func===========================================================================

    public void update() {
        DateTime now = DateTime.now();
        if (getUpdateTime() == null || !new LocalDate(now).equals(new LocalDate(getUpdateTime()))) {
            setUpdateTime(now);
            setFreeTimes(data().getFreenum());
        }
    }

    public summonpooldate data() {
        return DataCenter.getData(getDataId(), summonpooldate.class);
    }

    public void freeonce() {
        int gachaTimes = getFreeTimes();
        gachaTimes -= 1;
        setFreeTimes(gachaTimes);
    }

    public long resetTime() {
        DateTime now = DateTime.now();
        DateTime resetTime = new LocalDate(now).plusDays(1).toDateTimeAtStartOfDay();
        return resetTime.getMillis() - now.getMillis();
    }

    public void gachaed() {
        setGachaed(true);
    }
}
